window.onload=function () {
    var sltCity = document.getElementById('sltCity');
    initSelect('sltCity','--所有城市---',cities);
    sltCity.onchange = cityChange;

}


function cityChange() {

  var selectedValue=  this.selectedOptions[0].value;
  var selectedAreas= cities.find(function (item) {
      return item.id== selectedValue;
  }).areas;
  initSelect('sltArea','---所有区--',selectedAreas);

}

function initSelect(selector,allTips,opts) {
/*    var selector = 'sltCity';
    var allTips = '--所有城市---';
    var opts=cities;*/

    var slt = document.getElementById(selector);
    slt.innerHTML = "";
    opts.unshift({
        id:0,
        name:allTips
    })
    for (var i=0;i<opts.length;i++){
        var opt = document.createElement('option');
        opt.value = opts[i].id;
        opt.text = opts[i].name;
        slt.appendChild(opt);
    }
}


